﻿namespace Net8.Identity.MvcClient.Extensions
{
    public static class RegisterMiddlewares
    {
        public static WebApplication SetupMiddlewares(this WebApplication app)
        {
            if (app.Environment.IsDevelopment())
            {
                // 开发环境：显示详细的异常页面
                app.UseDeveloperExceptionPage();
            }
            else
            {
                // 默认环境：使用简洁的错误页面
                app.UseExceptionHandler("/Error");
                // 默认HSTS值为30天
                app.UseHsts();
            }

            app.UseHttpsRedirection();
            app.UseStaticFiles();
            app.UseRouting();

            app.UseAuthentication();
            app.UseAuthorization();

            app.MapControllers();
            return app;
        }
    }
}
